<?php
/**
 * Author: DRERY <rui1642@foxmail.com>
 */

/**
 * @var $list \common\models\Statistics[]
 * @var $this \yii\web\View
 */
\yii\bootstrap\BootstrapAsset::register($this);
\yii\web\JqueryAsset::register($this);
$JS = <<<JS
function getSum(fieldName) {
  var sum = 0;
  $('.data-' + fieldName).each(function() {
    sum += parseInt($(this).text());
  })
  $('.sum-' + fieldName).text(sum);
}
getSum('tph');
getSum('eph');
getSum('tky');
getSum('eky');
getSum('twh');
getSum('ewh');
JS;
$this->registerJs($JS);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html >
<html>
    <head>
        <meta charset="<?= Yii::$app->charset ?>">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="renderer" content="webkit">
        <meta http-equiv="Cache-Control" content="no-siteapp"/>
        <title>车辆从事运输类型表</title>
        <?php $this->head() ?>
        <style>
            img{
                max-width: 100%;
            }
        </style>
    </head>
    <body style="max-width: 640px;margin: auto;">
    <?php $this->beginBody() ?>
        <table class="table table-bordered">
            <tr>
                <td rowspan="2" align="middle" style="line-height: 50px;"></td>
                <td colspan="2" align="middle">普货数量</td>
                <td colspan="2" align="middle">客运数量</td>
                <td colspan="2" align="middle">危货数量</td>
            </tr>
            <tr align="middle">
                <td>实有数量</td>
                <td>注册数量</td>
                <td>实有数量</td>
                <td>注册数量</td>
                <td>实有数量</td>
                <td>注册数量</td>
            </tr>
            <?php foreach ($list as $stat) :?>
                <?php $counts = $stat->getExitsHtypeCount();?>
            <tr align="right">
                <td align="middle"><?=$stat->region?></td>
                <td class="data-tph"><?=$stat->puhuo_count?></td>
                <td class="data-eph"><?=$counts['puhuo']?></td>
                <td class="data-tky"><?=$stat->keyun_count?></td>
                <td class="data-eky"><?=$counts['keyun']?></td>
                <td class="data-twh"><?=$stat->weihuo_count?></td>
                <td class="data-ewh"><?=$counts['weihuo']?></td>
            </tr>
            <?php endforeach;?>
            <tr align="right">
                <td align="middle">合计</td>
                <td class="sum-tph"></td>
                <td class="sum-eph"></td>
                <td class="sum-tky"></td>
                <td class="sum-eky"></td>
                <td class="sum-twh"></td>
                <td class="sum-ewh"></td>
            </tr>
        </table>
    <?php $this->endBody() ?>
    </body>
</html>
<?php $this->endPage() ?>